////
//
/// \file ./include/inc/parser/block_node.hpp
//
//  Copyright 2007, 2008 Chandler Carruth
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations
//  under the License.
//
////

#ifndef inc_parser_block_node_header
#define inc_parser_block_node_header

#include <string>
#include <vector>

#include <boost/shared_ptr.hpp>

#include <inc/parser/parse_tree_node.hpp>

namespace inc {
namespace parser {

class BlockEntryNode;

/// \brief  Parse node for code blocks
/// \author Chandler Carruth
/// \date   2008.05.25
///
/// This is the generic parse node representing a block of executable code,
/// including flow control and statements. This is provided as a generic point
/// beyond which the context of the executed block can be ignored. It is
/// implemented in terms of a sequence of entries. This sequence guarantees
/// nothing about the storage of entries other than their order.

class BlockNode : public ParseTreeNode
{
public:
  typedef std::vector< boost::shared_ptr< BlockEntryNode > > EntrySequence;
  typedef EntrySequence::iterator EntryIterator;
  typedef EntrySequence::const_iterator EntryConstIterator;

  BlockNode();
  virtual ~BlockNode();

  virtual bool parse( const iterator& first,
                      const iterator& last,
                      iterator& last_parsed );

  /// \brief Query the number of entries in the block
  virtual size_t entries_size() const { return entries.size(); }

  /// \brief Query if there are any entries in the block
  virtual size_t entries_empty() const { return entries.empty(); }

  /// \brief Accessor for the first of the entries sequence: [first,last)
  virtual EntryConstIterator entries_first() const { return entries.begin(); }

  /// \brief Accessor for the last of the entries sequence: [first,last)
  virtual EntryConstIterator entries_last() const { return entries.end(); }

private:
  EntrySequence entries;
};

} //  end parser namespace
} //  end inc namespace
#endif  //  inc_parser_block_node_header
